import {cacheTools, getMultiLang} from 'nc-lightapp-front';
import requestApi from "./requestApi";
let linkVoucherApi = {
    link : (opt) => {
        let props = opt.data.props;
        let record = opt.data.record;
        let appid = opt.data.appid;
        let dataArrayForPz = [];
        requestApi.query({
            data: {
                id : record.relationID, //单据pk
                tradetype : record.pk_billtype
            },
            success: (data) => {
                if (data) {
                    let voucherMapKey = appid + data.desAppInfo.src;
                    if(data.isPreVoucher=="true"){
                        let voucherdata = data.data;
                            let dataForPz = {
                                pk_billtype : voucherdata.pk_billtype,
                                pk_group : 'GLOBLE00000000000000',
                                pk_org : voucherdata.pk_org,
                                relationID : voucherdata.relationID
                            }
                            dataArrayForPz.push(dataForPz);
                        let lbilltype = voucherdata.defdoc1;
                        let senddata = {"messagevo":dataArrayForPz,"desbilltype": ["C0"],"srcbilltype":lbilltype}
                        cacheTools.set(voucherMapKey,senddata);
                    }else{
                        if (data.desAppInfo.des){
                            //跳转到凭证
                            if (data.desAppInfo.pklist){
                                if (data.desAppInfo.pklist.length == 1){
                                    props.openTo(data.desAppInfo.url, {
                                        status: 'browse',
                                        appcode: data.desAppInfo.appcode,
                                        pagecode: data.desAppInfo.pagecode,
                                        id: data.desAppInfo.pklist[0],
                                        // n: this.state.json['public-000231'],//'联查凭证'
                                        n: '联查凭证',//'联查凭证'
                                        pagekey:'link',
                                        backflag:'noback'
                                    });
                                    return;
                                }else{
                                    cacheTools.set(data.desAppInfo.cachekey, data.desAppInfo.pklist);//之前缓存的key是”checkedData”,现在改为data.desAppInfo.cachekey,从接口获取缓存的key
                                    props.openTo(data.desAppInfo.url, {
                                        status: 'browse',
                                        appcode: data.desAppInfo.appcode,
                                        pagecode: data.desAppInfo.pagecode,
                                        // n: this.state.json['public-000231'], //'联查凭证'
                                        n: '联查凭证',//'联查凭证'
                                        scene: voucherMapKey //多笔联查新加scene字段
                                    });
                                    return;
                                }
                            }
                        }else{
                            //跳转到会计平台
                            cacheTools.set(voucherMapKey, data.desAppInfo.pklist);
                        }
                    }

                    //打开凭证节点
                    props.openTo(data.desAppInfo.url, {
                        status: 'browse',
                        appcode: data.desAppInfo.appcode,
                        pagecode: data.desAppInfo.pagecode,
                        scene: voucherMapKey,
                        // n: that.state.json['public-000232'] // '凭证预览' 凭证使用这个参数,会计平台不用
                        n: '凭证预览' // '凭证预览' 凭证使用这个参数,会计平台不用
                    });
                }
            }
        })
    }
}
export default linkVoucherApi;